﻿using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour {

    public GameObject bird;
    private Rigidbody birdBody;
    public float birdXSpeed = 2, birdYSpeed = 5;
    public Canvas readyCanvas;
    public GameObject bg1, bg2;
    private float birdX, bg1X, bg2X, bg1XSize, bg2XSize;
	// Use this for initialization
	void Start () {
        birdBody = bird.GetComponent<Rigidbody>();
    }
	
	// Update is called once per frame
	void Update () {
        if (Input.GetMouseButton(0))
        {
            birdBody.useGravity = true;
            birdBody.velocity = new Vector3(birdXSpeed, birdYSpeed, 0);
            readyCanvas.gameObject.SetActive(false);
        }
        transform.position = new Vector3(bird.transform.position.x, transform.position.y, transform.position.z);
        if (bird.transform.position.x > bg1.transform.position.x + bg1.transform.localScale.x)
        {
            bg1.transform.position = new Vector3(bg2.transform.position.x + bg2.transform.localScale.x, bg1.transform.position.y, bg1.transform.position.z);
        }
        if (bird.transform.position.x > bg2.transform.position.x + bg2.transform.localScale.x)
        {
            bg2.transform.position = new Vector3(bg1.transform.position.x + bg1.transform.localScale.x, bg2.transform.position.y, bg2.transform.position.z);
        }
    }
}
